package org.moonlight.jvm.instructions.stack.swap;

import org.moonlight.jvm.instructions.base.NoOperandsInstruction;
import org.moonlight.jvm.rtda.exclusive.Frame;
import org.moonlight.jvm.rtda.exclusive.OperandStack;
import org.moonlight.jvm.rtda.exclusive.Slot;

/**
 * SWAP: 交换 操作数栈栈顶 的两个变量
 *
 * @author Moonlight
 * @createTime 2023/8/16 17:30
 **/
public class Swap extends NoOperandsInstruction {

    @Override
    public void execute(Frame frame) {
        OperandStack stack = frame.getOperandStack();

        Slot a = stack.popSlot();
        Slot b = stack.popSlot();

        stack.pushSlot(a);
        stack.pushSlot(b);
    }

}
